package jwdt.xadmin.added.service.impl;

import jwdt.common.dao.BaseDao;
import jwdt.xadmin.added.bean.TLeadmail;
import jwdt.xadmin.added.service.LeadmailManageService;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.util.DateUtil;

public class LeadmailManageServiceImpl implements LeadmailManageService{

	private BaseDao<TLeadmail> baseDao;
	
	public void setBaseDao(BaseDao<TLeadmail> baseDao) {
		this.baseDao = baseDao;
	}
	
	@Override
	public PageUtil doList(PageUtil pu,TLeadmail leadmail) throws Exception{
		String where = " 1=1";
		String topic = leadmail.getTopic();
		String havereply = leadmail.getHavereply()==null?"":leadmail.getHavereply()+"";
		if(topic !=null && !"".equals(topic)){
			where +=  " and topic like '%" + topic +"%'";
		}
		if(havereply!=null && !"".equals(havereply)){
			where += " and havereply = '"+ havereply + "'";
		}
		String sql = where + " order by havereply asc,replytime desc";
		pu.doList(TLeadmail.class,sql);
		//创造json数据对象
		return pu;
	}
	@Override
	public String doAddact(TLeadmail obj) throws Exception {
		return baseDao.doAddObj(obj);
	}

	@Override
	public String doEditact(TLeadmail obj, int id) throws Exception {
		obj.setReplytime(DateUtil.getDateTime());
		obj.setHavereply(1);
		return baseDao.doUpdateObj(TLeadmail.class, id, obj);
	};
	
	@Override
	public String doDelact(int id) throws Exception {
		return baseDao.doDelObj(TLeadmail.class, id);
	}

	@Override
	public TLeadmail doLoad(int id) throws Exception {
		return baseDao.doLoadObj(TLeadmail.class, id);
	}
	@Override
	public String doUpdateState(int id, String result) throws Exception {
		return baseDao.doIntUpdateState(TLeadmail.class, "id="+id, result);
	}
}
